<template>
	<uni-popup ref="NavigationPopup" type="bottom" :is-mask-click="false">
	<view class="popup">
	  <view class="" @click="daohang('bai')">百度地图</view>
	  <view class="" @click="daohang('de')">高德地图</view>
	  <view class="" @click="daohang('teng')">腾讯地图</view>
	  <view class="" @click="closeNavigaPad()">取消</view>
	</view>
	</uni-popup>
</template>

<script setup lang="ts">
	import {ref} from 'vue';
	const NavigationPopup = ref(null);
	const props = defineProps({
	  currentLot: { type: Number },
	  currentLat: { type: Number },
	  longitude: { type: Number },
	  latitude: { type: Number },
	  addres:{ type: String },
	  name:{ type: String },
	});
	function NavigationLoc(){
	  // #ifdef H5
	  openNavigaPad()
	  // #endif
	  // #ifdef MP-WEIXIN
	  const latitude=parseFloat(props.longitude)
	  const longitude=parseFloat(props.latitude)
	   uni.openLocation({
	    latitude, //要去的纬度-地址
	    longitude, //要去的经度-地址
	    name: props.name, //地址名称
	    address: props.addres, //详细地址名称
	    success: function() {
	      console.log('导航成功');
	    },
	    fail: function(error) {
	      const errors=JSON.stringify(error)
	      uni.showToast({
	        icon:'none',
	        title:errors
	      })
	    },
	  });
	  // #endif
	}
	function daohang(type){
	      let position = {
	        latitude: props.latitude,
	        longitude:props.longitude,
	      };
	      let addres = props.addres;
	      switch (type) {
	        //高德地图高航
	        case 'de':
	          window.location.href = `https://uri.amap.com/navigation?from=${props.currentLot},${props.currentLat},当前位置&to=${
	            props.longitude
	          },${props.latitude},${addres}&mode=car&policy=1&src=${
	            addres
	          }&coordinate=gaode&callnative=1`;
	          break;
	        //百度地图导航
	        case 'bai':
	          window.location.href = `http://api.map.baidu.com/direction?origin=latlng:${props.currentLat},${
	            props.currentLot
	          }|name:当前位置&destination=${position}|name:${addres},&mode=driving&region=henan&output=html&src=webapp.baidu.openAPIdemo`;
	          break;
	        //腾讯地图导航
	        case 'teng':
	          window.location.href = `http://apis.map.qq.com/uri/v1/routeplan?type=drive&to=${addres}&tocoord=${position}&referer=dfdfd`;
	          break;
	      }
	}
	function openNavigaPad() {
	  NavigationPopup.value.open();
	}
	function closeNavigaPad() {
	  NavigationPopup.value.close();
	}
	defineExpose({ NavigationLoc });
</script>

<style lang="less">
	.popup{
		width: 100%;
		view{
			width: 100%;
			padding: 25rpx 0px;
			box-sizing: border-box;
			background-color: white;
			text-align: center;
			font-size: 32rpx;
		}
		view:nth-of-type(2){
			border-bottom: 1px solid #eee;
			border-top: 1px solid #eee;
		}
		view:nth-last-child(1){
			margin-top: 20rpx;
		}
	}
</style>